<script setup lang="ts">
// #ifdef MP
import { onAddToFavorites, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
import { wxCollect, wxShare } from '@/libs/share'

onShareAppMessage(wxShare(true))
onShareTimeline(wxShare(false))
onAddToFavorites(wxCollect())
// #endif

import { ref } from 'vue'

const props = defineProps<{
  /** 登陆后返回home页 */
  tohome?: string
  /** 登陆后重定向 */
  redirect?: string
  /** 登陆后重进入 */
  relaunch?: string
}>()

/** 是否返回原页面 */
const finishTodo: {
  type: 'back' | 'redirect' | 'relaunch' | ''
  url: string
} = {
  type: '',
  url: '',
}

if (props.tohome) {
  finishTodo.type = ''
} else if (props.redirect) {
  finishTodo.type = 'redirect'
  finishTodo.url = props.redirect
} else if (props.relaunch) {
  finishTodo.type = 'relaunch'
  finishTodo.url = props.relaunch
} else {
  finishTodo.type = 'back'
}

/** 手机号 */
const phonenumber = ref('')
/** 验证码 */
const captcha = ref('')

const toEdit = () => uni.redirectTo({ url: '/pages/user/edit-userdata/index' })
</script>

<template>
  <PageWrapper name="user-login">
    <div class="login">
      <input
        class="input"
        type="number"
        maxlength="11"
        placeholder="请输入手机号"
        v-model="phonenumber"
      />

      <input
        class="input"
        type="number"
        maxlength="6"
        placeholder="请输入验证码"
        v-model="captcha"
      />

      <button @click="toEdit">登录</button>
    </div>
  </PageWrapper>
</template>

<style lang="less" scoped>
.login {
  width: 100%;
  height: 100%;

  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20rpx;

  .input {
    width: 80%;
    height: 70rpx;
    padding: 0 20rpx;

    border: 2rpx solid #000;
    border-radius: 20rpx;
  }
}
</style>